<?php
/* @var $this PartyController */
/* @var $model Party */

$this->breadcrumbs=array(
	'[用户]管理'=>array('admin'),
	'[用户]列表',
);
//设置页面标题
$this->pageTitle=Yii::app()->name.' - [用户]列表';
$this->contentTitle='[用户]列表';
?>
<!-- 查询表单 -->
<?php $this->renderPartial('_search',array(
	'model'=>$model,
)); ?>
<!-- 查询表单 -->

<!-- 数据表格 -->
<table cellspacing="1" class="mylist2">
	<thead>
		<tr class="mylist_title">
			<td width="3%"><input type="checkbox" class="checkbox" onclick="InverSelect();" /></td>
			<td><?php echo CHtml::encode($model->getAttributeLabel('id')); ?></td>
                        <td><?php echo CHtml::encode($model->getAttributeLabel('crowd_id')); ?></td>
			<td><?php echo CHtml::encode($model->getAttributeLabel('username')); ?></td>
			<td><?php echo CHtml::encode($model->getAttributeLabel('phone')); ?></td>
			<td><?php echo CHtml::encode($model->getAttributeLabel('sex')); ?></td>
                        <td>参加活动次数</td>
			<td><?php echo CHtml::encode($model->getAttributeLabel('province')); ?></td>
			<td><?php echo CHtml::encode($model->getAttributeLabel('city')); ?></td>
			<td><?php echo CHtml::encode($model->getAttributeLabel('area')); ?></td>
                        <td><?php echo CHtml::encode($model->getAttributeLabel('address')); ?></td>
			<td><?php echo CHtml::encode($model->getAttributeLabel('company')); ?></td>
			<td><?php echo CHtml::encode($model->getAttributeLabel('recommend')); ?></td>
                        <td><?php echo CHtml::encode($model->getAttributeLabel('head_image')); ?></td>
			<td><?php echo CHtml::encode($model->getAttributeLabel('is_from')); ?></td>
                        <td>黑名单操作</td>
               

		</tr>
	</thead>
	<tbody>
		<?php
                foreach ($data->getData() as $key => $value) {
                    $province='';
                    $city='';
                    $area='';
                    $model_p=Party::model()->find("is_use=1 and phone='".$value->phone."' and code='".$value->code."'");
                    $model_n=Naddress::model()->find("is_used=1 and phone='".$value->phone."' and code='".$value->code."'");
                    if(count($model_p)>0){
                         $province=$model_p->province;
                         $city=$model_p->city;
                         $area=$model_p->area;
                        
                    }else if(count($model_n)>0){
                         $province=$model_n->province;
                         $city=$model_n->city;
                         $area=$model_n->area;
                    }else{
                         $province=$value->province;
                         $city=$value->city;
                         $area=$value->area;
                    }
                    
                ?>
		<tr class="datalist">
			<td align="center"><input name="id[]" type="checkbox" value="<?php echo CHtml::encode($value->id); ?>" class="checkbox" /></td>
			<td><?php echo CHtml::encode($value->id);?></td>
                        <td><?php echo CHtml::encode($value->crowd->title);?></td>
			<td><?php echo CHtml::link($value->username, array('party/update','id'=>$value->id)); ?></td>
			<td><?php echo CHtml::encode($value->phone);?></td>
			<td><?php echo CHtml::encode($value->sex);?></td>
                        <td><?php echo PartyController:: getCount($value->phone,$value->code);?></td>
			<td><?php echo CHtml::encode($province);?></td>
			<td><?php echo CHtml::encode($city);?></td>
			<td><?php echo CHtml::encode($area);?></td>
			<td><?php echo CHtml::encode($value->address);?></td>
			<td><?php echo CHtml::encode($value->company);?></td>
			<td><?php echo CHtml::encode($value->recommend);?></td>
			<td align="center">
                            <?php 
                                $images='';
                                if(!empty($value->head_image))
                                    $images=$value->head_image;
                                else
                                    $images=Yii::app()->baseUrl.'/images/wu.png';
                            ?>
                            <img width="50px" height="50px" src="<?php echo $images?>">
                        </td>
                         <td>
                        <?php 
                            if($value->is_from==0){
                                echo CHtml::link('未来', 'javascript:notTo('.$value->id.');');
                            }elseif ($value->is_from==1) {
                                echo CHtml::link('已来', 'javascript:haveTo('.$value->id.');');    
                            }  else {
                                echo CHtml::link('已取消', 'javascript:cancelTo('.$value->id.');');  
                            }
                            ?>
                         </td>
                        <td align="center"><?php
                            $count=Blacklist::model()->count("phone='".$value->phone."' and code='".$value->code."'");
                            if($count<=0){
                                 echo CHtml::link('拉黑', 'javascript:updateSelect('.$value->id.');');
                               
                            }else{
                                 echo CHtml::link('取消拉黑', 'javascript:canceSelect('.$value->id.');');
                            }
                            ?>
                        </td>
		</tr>
		<?php }?>

	</tbody>
</table>
<!-- 数据表格 -->

<!-- 数据分页 -->
<div class="mylist_foot">
    <div class="fl p10 btn"><a href="javascript:deleteSelect(0);">批 量 删 除</a></div>
    <div class="fl p10 btn"><a href="javascript:updateSelect(0);">批 量 拉 黑</a></div>
    <div class="fl p10 btn"><a href="<?php echo Yii::app()->createUrl('Party/upload'); ?>">EXCEL导入</a></div>
    <div class="fl p10 btn"><?php echo CHtml::link('添 加', array('party/create')); ?>
</div>
	<div class="pagecss fr">
	<?php $this->widget("CLinkPager", array(
        "pages" => $data->pagination,
        "header"=>"跳转到：",
        "prevPageLabel"=>"&lt; 上一页",
        "nextPageLabel"=>"&gt; 下一页",
        "firstPageLabel"=>"&lt;&lt; 首页",
        "lastPageLabel"=>"&gt;&gt; 尾页",
        "maxButtonCount"=>5,
        "footer"=>"当前页数：".($data->pagination->currentPage+1)." 总页数：".$data->pagination->pageCount." 总记录数：".$data->pagination->itemCount
    )) ?>
	</div>
</div>

<?php if(Yii::app()->user->hasFlash('success'))
        echo "<script> art.dialog({
        id: 'dialogTest',
        title: '提示信息',
        time: 5,
        icon: 'succeed',
        content: '<b>操作成功！</b><br /><br />该消息5秒后自动消失！',
        button: [
            {
                name: '确定',
                focus: true
            }]
    });</script>" 

?><!-- 数据分页 -->
<!-- 脚本 -->
<script type="text/javascript">
    function deleteSelect(id){
        ajaxSubmitdeleteSelect(id,'<?php echo Yii::app()->createUrl('party/delete',array('id'=>0)) ?>
');
    }
    function updateSelect(id){
        ajaxSubmitUpdateSelect(id,'<?php echo Yii::app()->createUrl('party/blackList',array('id'=>0)) ?>
');
    }
     function canceSelect(id){
        ajaxSubmitUpdateSelect(id,'<?php echo Yii::app()->createUrl('party/cancelList',array('id'=>0)) ?>
');
    }
    function notTo(id){
        ajaxSubmitChangeParty(id,1,'<?php echo Yii::app()->createUrl('party/changeParty',array('id'=>0)) ?>
');
    } 
    function haveTo(id){
        ajaxSubmitChangeParty(id,3,'<?php echo Yii::app()->createUrl('party/changeParty',array('id'=>0)) ?>
');
    }   
    function cancelTo(id){
        ajaxSubmitChangeParty(id,0,'<?php echo Yii::app()->createUrl('party/changeParty',array('id'=>0)) ?>
');
    }        
    
    function ajaxSubmitUpdateSelect(id,url){
        if(id==0){
            var ids=new Array();
            $('input[name="id[]"]').each(function(){
                if($(this).attr("checked"))
                    ids.push($(this).val());
            });
            id=ids;
        }
        art.dialog({
                lock: true,
                background: '#600',
                opacity: 0.6,
                content: '确认修改？',
                icon: 'warning',
                ok:function(){
                    $.ajax({
                        type:"POST",
                        dataType:"json",
                        data:{"id[]":id},
                        url:url,
                        success:function(json) {
                            if(json.result==0){
                                location.reload();
                            }else{
                                art.dialog({icon:'error',content:'操作数据失败。。。',time:1});
                            }
                        }
                    });
                },
                cancel: function(){}
     });
}
    function ajaxSubmitChangeParty(id,type,url){
        if(id==0){
            var ids=new Array();
            $('input[name="id[]"]').each(function(){
                if($(this).attr("checked"))
                    ids.push($(this).val());
            });
            id=ids;
        }
        art.dialog({
                lock: true,
                background: '#600',
                opacity: 0.6,
                content: '确认修改？',
                icon: 'warning',
                ok:function(){
                    $.ajax({
                        type:"POST",
                        dataType:"json",
                        data:{"id":id,'type':type},
                        url:url,
                        success:function(json) {
                            if(json.result==0){
                                location.reload();
                            }else{
                                art.dialog({icon:'error',content:'操作数据失败。。。',time:1});
                            }
                        }
                    });
                },
                cancel: function(){}
     });
}
</script>
<!-- 脚本 -->
  <?php 
        if(Yii::app()->user->getFlash('upload_success')){
        echo "<script>art.dialog({icon:'succeed',content:'已导入！',time:1});</script>";
        }    
    ?>